from jinja2 import Environment, FileSystemLoader
import json
from string_utils import manipulation

def main():
    env = Environment(loader=FileSystemLoader('./'))
    tpl = env.get_template('tespojo.tpl')
    f = open('order.json', 'r')
    columnContent = f.read()
    columnsJson: dict = {}
    columnsJson = json.loads(columnContent)
    f.close()
    columnsList: list = []
    typeMap: dict = {
        "integer": "Integer",
        "keyword": "String",
        "long": "Long",
        "text": "String",
        "short": "Integer",
    }

    for item in columnsJson.items():
        column: dict = {}
        column['name'] = manipulation.snake_case_to_camel(item[0],False)
        column['estype'] = item[1]['type']
        column['javatype']= typeMap[column['estype']]
        columnsList.append(column)

    with open('OrdersEsDTO.java', 'w+') as fout:
        render_content = tpl.render({
            "class_name":"OrdersEsDTO",
            "columns": columnsList
        })
        fout.write(render_content)


if __name__ == '__main__':
    main()